package com.tai.line;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.media.MediaPlayer;

public class tool {
	public static Bitmap resizeBitmap(Bitmap bitmap,int newWidth, int newHeight){
		int width=bitmap.getWidth();
		int height=bitmap.getHeight();
		float scaleWidth=((float)newWidth)/width;
		float scaleHeight=((float)newHeight)/height;
		Matrix matrix=new Matrix();
		matrix.postScale(scaleWidth, scaleHeight);
		Bitmap bit=Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
		if(bit!=null) return bit;
		return null;
	}
	public static Bitmap []bitmapArray(Bitmap bitmap, Context context){
		Bitmap []bit=new Bitmap[15];
		
		int w = bitmap.getWidth() / 8;
		
		for(int i=0;i<8;i++){
			bit[i]=Bitmap.createBitmap(bitmap, i*w, 0, w, bitmap.getHeight());
			bit[i]=resizeBitmap(bit[i],30,30);
		}
		for(int j=1;j<8;j++)
		{
			bit[j+7] = Bitmap.createBitmap(30, 30, Bitmap.Config.ARGB_8888);
	    	Canvas myC = new Canvas(bit[j+7]);
	    	//myC.drawColor(context.getResources().getColor(R.color.backgroud));
			myC.drawBitmap(resizeBitmap(bit[j],10,10), 10, 10, new Paint());
			
			//bit[j+7]=resizeBitmap(bit[j],15,15);
		}
			
		return bit;
	}
	
	public static Bitmap[] bitmapArray(Context context)//tạo mấy quả bóng: bóng to và bóng nhỏ
	{
		Bitmap[] bit = new Bitmap[15];
		bit[0] = null;
		bit[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.ball1);
		bit[2] = BitmapFactory.decodeResource(context.getResources(), R.drawable.ball2);
		bit[3] = BitmapFactory.decodeResource(context.getResources(), R.drawable.ball3);
		bit[4] = BitmapFactory.decodeResource(context.getResources(), R.drawable.ball4);
		bit[5] = BitmapFactory.decodeResource(context.getResources(), R.drawable.ball5);
		bit[6] = BitmapFactory.decodeResource(context.getResources(), R.drawable.ball6);
		bit[7] = BitmapFactory.decodeResource(context.getResources(), R.drawable.ball7);
		
		int w = bit[1].getWidth();
		int h = bit[1].getHeight();
		for(int j=1;j<8;j++)
		{
			bit[j+7] = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);//tao bit map tư 7-15,đặt canvas làm nền cho bit map,
	    	Canvas myC = new Canvas(bit[j+7]);
			myC.drawBitmap(resizeBitmap(bit[j],10,10), 10, 10, new Paint());//set lại kích thước quả bóng
			
			//bit[j+7]=resizeBitmap(bit[j],15,15);
		}
		
		
		return bit;
	}
	public static void playSound(int IDSound, Context context ){
		MediaPlayer mp = MediaPlayer.create(context, IDSound);
		mp.start();
		
	}
}
